package mysql

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/gohouse/gorose/v2"
)

var engin *gorose.Engin

func InitMysql(Mysql_Host, Mysql_port, Mysql_ID, Mysql_pwd, Mysql_db string) {

	DbConfig := gorose.Config{
		Driver:          "mysql",
		Dsn:             Mysql_ID + ":" + Mysql_pwd + "@tcp(" + Mysql_Host + ":" + Mysql_port + ")/" + Mysql_db + "?charset=utf8&parseTime=true",
		Prefix:          "",
		SetMaxOpenConns: 400,
		SetMaxIdleConns: 15,
	}
	var err error
	fmt.Println("connect to mysql...")
	engin, err = gorose.Open(&DbConfig)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("connect to mysql success")
}

func DB() gorose.IOrm {
	return engin.NewOrm()
}
